# -*- encoding=utf8 -*-
__author__ = "yangxianming"

from airtest.core.api import *
# ST.PROJECT_ROOT = "E:\AirtestWorkSpace\fuyuanwaiUItest"
# using(r"E:\AirtestWorkSpace\fuyuanwaiUItest\common.air")
# from common import *

auto_setup(__file__)

#拿到设备编号
import sys
args = sys.argv
devicePid = args[4].split("/")[3]
print("--------" + devicePid)
rootArr = args[2].split("\\")
scriptRoot = ""
for i in range(len(rootArr) - 1):
    scriptRoot = scriptRoot + rootArr[i] + "\\"
print("--------" + scriptRoot)

#对更目录下设变编号文件做注册登记操作 1代表在使用  0代表停止使用
with open(scriptRoot + devicePid, 'w') as f:
    f.write('1')
    
using(scriptRoot + "common.air")
from common import *
stop_app("com.alibaba.android.rimet")
start_app("com.alibaba.android.rimet")

try:
    sleep(1.0)
    openKoufu()
    sleep(1.0)
    openScene("dangaolinshi")
    
    ##先睡10s
    sleep(10.0)
    #点击搜索
    touch(Template(r"tpl1681112207619.png", record_pos=(0.046, -0.599), resolution=(1080, 1920)))
    sleep(1.0)
    touch(Template(r"tpl1681112234506.png", record_pos=(-0.03, -0.596), resolution=(1080, 1920)))
    sleep(1.0)
    text("三只松鼠")
    sleep(5.0)
    #点击左边，无关什么商品
    touch((280, 750))
    sleep(1.0)
    #点击立即预定
    touch(Template(r"tpl1681113141087.png", record_pos=(0.33, 0.82), resolution=(1080, 1920)))
    sleep(1.0)
    touch(Template(r"tpl1681113161068.png", record_pos=(0.28, 0.819), resolution=(1080, 1920)))
    sleep(4.0)
    touch(Template(r"tpl1681113187782.png", record_pos=(0.365, -0.353), resolution=(1080, 1920)))
    sleep(1.0)
    touch(Template(r"tpl1681113208897.png", record_pos=(0.376, 0.805), resolution=(1080, 1920)))
    sleep(5.0)
    
    assert_exists(Template(r"tpl1681979081149.png", record_pos=(-0.278, 0.731), resolution=(1080, 1920)), "验证是否回到我们的收银台")

    

except Exception as e:
    print(e)
finally:
    sleep(1.0)
    stop_app("com.alibaba.android.rimet")
    #完成测试等级设备为0以便被其他脚本使用
    with open(scriptRoot + devicePid, 'w') as f:
        f.write('0')


